﻿
@{
    ViewBag.Title = "职员管理";
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
}

<div class="layui-tab layui-tab-brief" lay-filter="user">
    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 5px 0;">
        <form action="" class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="keyWord" class="layui-input" placeholder="请输入名称搜索">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn searchButton">搜索</button>
                    <a class="layui-btn" lay-href="/Management/Employee/Create">添加职员</a>
                </div>
            </div>
        </form>
    </div>

    <table class="layui-table" lay-data="{url:'/Management/Employee/GetData', cellMinWidth: 80, page: true,limit:15}" lay-filter="departmentList" id="departmentList">
        <thead>
            <tr>
                <th lay-data="{field:'EmpID', width:80}">工号</th>
                <th lay-data="{ field: 'EmpName',edit: 'text'}">姓名</th>
                <th lay-data="{ width:60, field: 'Sex'}">性别</th>
                <th lay-data="{ field: 'Birthday'}">生日</th>
                <th lay-data="{ field: 'Telephone'}">电话</th>
                <th lay-data="{ field: 'TelSimpleNum'}">短号</th>
                <th lay-data="{ field: 'Email'}">邮箱</th>
                <th lay-data="{field:'StatusName'}">状态</th>
                <th lay-data="{fixed: 'right', width:520, align:'center', toolbar: '#barDemo'}">操作</th>
            </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-href="/Management/Employee/Show?empID={{d.EmpID}}" lay-text="查看{{d.EmpName}}">查看</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-href="/Management/Employee/Edit/{{d.ID}}" lay-text="编辑{{d.EmpName}}">编辑</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:deleteItem({{d.ID}})">删除</a>

        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:resetPassword({{d.ID}})">重置密码</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:ShowPage('/Management/Employee/SetPosition?EmpID={{d.EmpID}}','设置岗位',8)">设置岗位</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-href="/Management/EmployeePosition/Index?empID={{d.EmpID}}" lay-text="查看{{d.EmpName}}岗位">查看岗位</a>

        {{# if(d.Status==-1){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:enabledItem({{d.ID}})">启用</a>
        {{# } else{ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:disEnabledItem({{d.ID}})">禁用</a>
        {{# } }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:ShowPage('/Management/Employee/Permission?empID={{d.EmpID}}','权限管理',10)">权限管理</a>
    </script>


</div>
<script type="text/javascript">
    function deleteItem(id) {
        layer.confirm('您确认删除当前职员吗？<p style="color:red;">老职员一般采用禁用即可，该功能一般用于新职员录入错误</p>', {
            btn: ['我要删除', '不小心点错了'], title: '职员删除确认' //按钮
        }, function () {
            var url = "/Management/Employee/Delete?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Msg);
                }
            });
        }, function () {

        });
    }

    function enabledItem(id) {
        layer.confirm('您确认启用当前职员吗？', {
            btn: ['我要启用', '不小心点错了'], title: '职员启用确认'
        }, function () {
            var url = "/Management/Employee/Enabled?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.msg("启用成功");
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Message);
                }
            });
        }, function () {

        });
    }

    function disEnabledItem(id) {
        layer.confirm('您确认需要禁用该职员？', {
            btn: ['我要禁用', '不小心点错了'], title: '职员禁用确认' //按钮
        }, function () {
            var url = "/Management/Employee/Disable?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.msg("禁用成功");
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Message);
                }
            });
        }, function () {

        });
    }

    function resetPassword(id) {
        layer.confirm('您确认重置当前职员登陆密码吗？', {
            btn: ['我要重置', '不小心点错了'], title: '密码重置确认' //按钮
        }, function () {
            var url = "/Management/Employee/ResetPassword?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.alert('密码重置成功，新密码为:' + data.Message, {
                        skin: 'layui-layer-molv'
                        , closeBtn: 0
                    });
                }
                else {
                    layer.msg(data.Message);
                }
            });
        }, function () {

        });
    }

    layui.use('table', function () {
        var table = layui.table;
        //监听单元格事件
        table.on('edit(departmentList)', function (obj) {
            if (obj.field === 'Name') {
                var url = "/Management/Employee/SetName?id=" + obj.data.ID + "&name=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("职员姓名修改成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Message);
                    }
                });
            }
            else if (obj.field === 'Sort') {
                var url = "/Management/Employee/SetSort?id=" + obj.data.ID + "&sort=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("排序修改成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Message);
                    }
                });
            }
        });

    });

</script>


